// JavaScript Document

$(document).ready(function() 
{
	//Valid current password
	$("#curPass").blur(function() 
	{ 	
		if($(this).val() == '')
		{
			$("#showMsgCurPass").html('<font id="error">Cannot be blank...</font>');
			document.getElementById("ChangeBtn").setAttribute('disabled','disabled'); //Check Fail disible submit button 
		}
		else
		{
			var data = {CurPass: $(this).val()};
			
			$.ajax
			({
				type: "POST",               	// Phương thức gởi đi
				url: "checkOldPass.php",  		// File xử lý dữ liệu được gởi
				data: data,            			// Dữ liệu gởi đến cho url 
				success: function(result) 		// Hàm chạy khi dữ liệu gởi thành công
				{ 	
					if(result == "true")
					{						
					$("#showMsgCurPass").html("<img src='images/tick.png' width='20px' height='20px' >");
					document.getElementById("ChangeBtn").removeAttribute('disabled'); //Check True enable submit button
					}
					else
					{
					$("#showMsgCurPass").html("<h3 id='error'>&nbsp;Password is wrong</h3>");
					document.getElementById("ChangeBtn").setAttribute('disabled','disabled'); //Check Fail disible submit button 
					}
				}
			});
		}
	});//End Valid current password
	
	// Check Length Password
	$("#newPass").blur(function() 
	{ 
		if($(this).val() == '') 
		{
			//Blank or not
			$("#showMsgNewPass").html('<font id="error">Cannot be blank...</font>');
			document.getElementById("ChangeBtn").setAttribute('disabled','disabled'); //Check Fail disible submit button 
		}
		else
		{	//Check length
			if(($(this).val().length) < 9) 
			{
				$("#showMsgNewPass").html('<font id="error">At least 9 characters</font>');
				document.getElementById("ChangeBtn").setAttribute('disabled','disabled'); //Check Fail disible submit button
			}
			else if(!($(this).val() == $("#curPass").val()))
			{
				$("#showMsgNewPass").html("<img src='images/tick.png' width='20px' height='20px' >");
				document.getElementById("ChangeBtn").removeAttribute('disabled'); //Check True enable submit button
			}
			else
			{
				$("#showMsgNewPass").html('<font id="error">It seems like the old one, try another !</font>');
				document.getElementById("ChangeBtn").setAttribute('disabled', 'disabled'); //Check Fail disible submit button
			}
			
		}
	});//End Length Password
	

	$("#connewPass").blur(function() 
	{ 
		if($(this).val() == '') 
		{
			//Blank or not
			$("#showMsgReNewPass").html('<font id="error">Cannot be blank...</font>');
			document.getElementById("ChangeBtn").setAttribute('disabled', 'disabled'); //Check Fail disible submit button
		}
		if(($(this).val().length) < 9)
		{
			$("#showMsgReNewPass").html('<font id="error">At least 9 characters</font>');
			document.getElementById("ChangeBtn").setAttribute('disabled', 'disabled'); //Check Fail disible submit button
		}
		else
		{	//Validate pass matched
			if(!($(this).val() == $("#newPass").val())) 
			{
				$("#showMsgReNewPass").html('<font id="error">Password are not matched</font>');
				document.getElementById("ChangeBtn").setAttribute('disabled', 'disabled'); //Check Fail disible submit button
			}
			else
			{
				$("#showMsgReNewPass").html("<img src='images/tick.png' width='20px' height='20px' >");
				document.getElementById("ChangeBtn").removeAttribute('disabled'); //Check True enable submit button
			}
		}
	});//End Check Password Match
	
	
	
	
	
	
});// End ready function